package config;

import io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.openapi.Configuration;
import io.kubernetes.client.util.ClientBuilder;
import io.kubernetes.client.util.KubeConfig;

import java.io.FileReader;

public class KubeConfigure {

    /**
     * Get k8s Configuration and set
     *
     * @return API client.
     */
    public static ApiClient GetKubeClient() {
        String kubeConfigPath = Constant.KUBE_CONFIG_PATH;
        ApiClient client = null;
        try {
            client = ClientBuilder.kubeconfig(KubeConfig.loadKubeConfig(new FileReader(kubeConfigPath))).build();
            Configuration.setDefaultApiClient(client);
            return client;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
